// ***************************************************************
// Table C1: Employment over parcel size by NAICS 3-digit industry
// ***************************************************************

// Writes the results as reg_montreal to $resultpath/tables/

use "$outpath/database_for_reg.dta", clear

eststo clear

gen ind_dens=employment*1000/P_area_c
label var ind_dens "Employment over parcel size (per 1,000 of sq meter)"

reghdfe Lnland_pwc Lnpopcma Lnareacma dist_min_NEW i.cat0 spacematep spacematep2 spacematep3 spacematep4 if samplep==1, absorb(naics4d eruid) cluster(cmauid)

keep if e(sample)==1

tostring naics3d, replace

replace naics3d="311 Food manufacturing" if naics3d=="311"
replace naics3d="312 Beverage product manuf." if naics3d=="312"
replace naics3d="313 Textile mills" if naics3d=="313"
replace naics3d="314 Textile product mills" if naics3d=="314"
replace naics3d="315 Clothing manufacturing" if naics3d=="315"
replace naics3d="316 Leather, allied product manuf." if naics3d=="316"
replace naics3d="321 Wood product manufacturing" if naics3d=="321"
replace naics3d="322 Paper manufacturing" if naics3d=="322"
replace naics3d="323 Printing, support activities" if naics3d=="323"
replace naics3d="324 Petrol, coal product manuf." if naics3d=="324"
replace naics3d="325 Chemical manufacturing" if naics3d=="325"
replace naics3d="326 Plastics, rubber products manuf." if naics3d=="326"
replace naics3d="327 Non-metallic mineral product manuf." if naics3d=="327"
replace naics3d="331 Primary metal manufacturing" if naics3d=="331"
replace naics3d="332 Fabricated metal product manuf." if naics3d=="332"
replace naics3d="333 Machinery manufacturing" if naics3d=="333"
replace naics3d="334 Computer, electronic product manuf." if naics3d=="334"
replace naics3d="335 Electrical, appliance manuf." if naics3d=="335"
replace naics3d="336 Transportation equipment manuf." if naics3d=="336"
replace naics3d="337 Furniture, related product manuf." if naics3d=="337"
replace naics3d="339 Miscellaneous manufacturing" if naics3d=="339"

preserve

collapse (count) obs=ind_dens (mean) meannaics3d=ind_dens (p50) p50naics3d=ind_dens (sd) cvnaics3d=ind_dens, by(naics3d)
replace cvnaics3d=cvnaics3d/meannaics3d
tostring naics3d, replace
save "$resultpath/tables/stat_ind_dens_naics.dta", replace

restore

preserve

collapse (count) obs=ind_dens (mean) meannaics3d=ind_dens (p50) p50naics3d=ind_dens (sd) cvnaics3d=ind_dens
replace cvnaics3d=cvnaics3d/meannaics3d
gen naics3digit="Total"
append using "$resultpath/tables/stat_ind_dens_naics.dta"
order naics3d obs mean p50 cv
sort naics3d

foreach v of var mean p50 cv{
	replace `v'=round(`v',0.01)
}

save "$resultpath/tables/stat_ind_dens_naics.dta", replace

restore

